package com.example.kiratest.test;

import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
import com.aliyun.tea.TeaException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AsessToken {

    /**
     * 使用 Token 初始化账号Client
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dingtalkoauth2_1_0.Client createClient() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
        config.protocol = "https";
        config.regionId = "central";
        return new com.aliyun.dingtalkoauth2_1_0.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dingtalkoauth2_1_0.Client client = AsessToken.createClient();
        com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest()
                .setAppKey("dingzrr5q24mlutd6knl")
                .setAppSecret("C2vkXuTegyUNsmftSKRgO4zq0lRuLBbw2oxxB_A_vzc0T0LHcsR2FxH3atMLDrlT");
        try {
            GetAccessTokenResponse accessToken = client.getAccessToken(getAccessTokenRequest);
            // 查看响应体结构，假设存在getToken方法获取具体的token信息
            if (accessToken.getBody() != null) {
                System.out.println("响应体信息: " + accessToken.getBody().toString());
                // 这里需要根据实际的响应体结构调整获取具体字段的方法
                // 例如，如果响应体中有accessToken字段
                // System.out.println("Access Token: " + accessToken.getBody().getAccessToken());
            } else {
                System.out.println("响应体为空");
            }
        } catch (TeaException err) {
            System.err.println("TeaException 错误信息: " + err.getMessage());
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                System.err.println("错误代码: " + err.code + ", 错误消息: " + err.message);
            }
        } catch (Exception _err) {
            TeaException err = new TeaException(_err.getMessage(), _err);
            System.err.println("通用异常错误信息: " + err.getMessage());
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                System.err.println("错误代码: " + err.code + ", 错误消息: " + err.message);
            }
        }
    }
}